//
//  JFData.m
//
//  Created by   on 2019/2/24
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "JFData.h"


NSString *const kJFDataId = @"id";
NSString *const kJFDataUid = @"uid";
NSString *const kJFDataType = @"type";
NSString *const kJFDataJifen = @"jifen";
NSString *const kJFDataTime = @"time";


@interface JFData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation JFData

@synthesize dataIdentifier = _dataIdentifier;
@synthesize uid = _uid;
@synthesize type = _type;
@synthesize jifen = _jifen;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.dataIdentifier = [self objectOrNilForKey:kJFDataId fromDictionary:dict];
            self.uid = [self objectOrNilForKey:kJFDataUid fromDictionary:dict];
            self.type = [self objectOrNilForKey:kJFDataType fromDictionary:dict];
            self.jifen = [self objectOrNilForKey:kJFDataJifen fromDictionary:dict];
            self.time = [self objectOrNilForKey:kJFDataTime fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.dataIdentifier forKey:kJFDataId];
    [mutableDict setValue:self.uid forKey:kJFDataUid];
    [mutableDict setValue:self.type forKey:kJFDataType];
    [mutableDict setValue:self.jifen forKey:kJFDataJifen];
    [mutableDict setValue:self.time forKey:kJFDataTime];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.dataIdentifier = [aDecoder decodeObjectForKey:kJFDataId];
    self.uid = [aDecoder decodeObjectForKey:kJFDataUid];
    self.type = [aDecoder decodeObjectForKey:kJFDataType];
    self.jifen = [aDecoder decodeObjectForKey:kJFDataJifen];
    self.time = [aDecoder decodeObjectForKey:kJFDataTime];

    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_dataIdentifier forKey:kJFDataId];
    [aCoder encodeObject:_uid forKey:kJFDataUid];
    [aCoder encodeObject:_type forKey:kJFDataType];
    [aCoder encodeObject:_jifen forKey:kJFDataJifen];
    [aCoder encodeObject:_time forKey:kJFDataTime];

}

- (id)copyWithZone:(NSZone *)zone {
    JFData *copy = [[JFData alloc] init];
    
    
    
    if (copy) {

        copy.dataIdentifier = [self.dataIdentifier copyWithZone:zone];
        copy.uid = [self.uid copyWithZone:zone];
        copy.type = [self.type copyWithZone:zone];
        copy.jifen = [self.jifen copyWithZone:zone];
    }
    
    return copy;
}


@end
